import random
import string
import hashlib

class LoginCode:
    def __init__(self):
        self.pid = '5-MC'
        self.key = 'TIYZ5GuvK2CEzfTHvK4Uw2TGxrkR5UT1'
        self.code = None

    def build(self, time):
        random = self.random()
        code = f'{self.pid}&{random}&{time}'
        self.code = f'{code}&{self.sign(code)}'
        return self.code

    def sign(self, code):
        code = f'{code}&{self.key}'
        md5 = hashlib.md5(code.encode('utf8'))
        return md5.hexdigest()

    def random(self, len = 12):   
        return ''.join(random.choices(string.ascii_letters + string.digits, k=len))